// components/simple-sort/simple-sort.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    type: {
      type: String,
      value: 'big'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentSelectIndex: 0,
    sortType: "",//升降序
    resultData: [
      {
        title: "默认",
        sortType: '',
        key: "all"
      },
      {
        title: "价格",
        sortType: '',
        key: "price"
      },
      {
        title: "销量",
        sortType: '',
        key: "sale"
      },
      {
        title: "新品",
        sortType: '',
        key: "new"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    simpleItemChange(e) {
      let index = e.currentTarget.dataset.index;
      if (index == this.data.currentSelectIndex && index != 0 && index != 3) {
        let item = this.data.resultData[index];
        item.sortType = item.sortType == 'asc' ? 'desc' : 'asc';
        //动态数组
        let changeItem = 'resultData[' + index + ']';
        this.setData({
          [changeItem]: item
        })
        this.triggerEvent('change', this.data.resultData[index]);
        console.log(this.data.resultData)
        this.setData({
          currentSelectIndex: index
        })
        return;
      }
      this.setData({
        currentSelectIndex: index
      })
      let arr = this.data.resultData;
      arr.forEach((i, idx) => {
        i.sortType = ''
        if (idx == index && index != 0 && index != 3) {
          i.sortType = 'asc'
        }
      })
      this.setData({
        resultData: arr
      })
      console.log(this.data.resultData);
      // console.log("JJLog:看看这个:", this.data.resultData[index]);
      // 方法回调：
      this.triggerEvent('change', this.data.resultData[index]);
    },
  }
})